// Functions for general use

import nme.display.MovieClip;

class Calc {
    public var parent:MovieClip;

	public function new(myParent:MovieClip) {
       parent = myParent; 
    }

    // A set of functions allowing percentage calculation for canvas placement.
    /// Convert an absolute X value to percentage of the canvas
    public function absXPer(absX:Float):Float { return parent.span / absX; }

    /// Convert an absolute Y value to percentage of the canvas
    public function absYPer(absY:Float):Float { return parent.depth / absY; }

    /// Convert a percentage X value to an absolute value on the canvas
    public function perXAbs(perX:Float):Float { return parent.span * perX; }

    /// Convert a percentage Y value to an absolute value on the canvas
    public function perYAbs(perY:Float):Float { return parent.depth * perY; }

    /// Convert an absolute point to a percentage point
    public function absPointPer(absPoint:Array<Float>):Array<Float> { return [absXPer(absPoint[0]), absYPer(absPoint[1])]; } 

    /// Convert an percentage point to an absolute point
    public function perPointAbs(perPoint:Array<Float>):Array<Float> { return [perXAbs(perPoint[0]), perYAbs(perPoint[1])]; }

	// Polished math functions
	public function max(a:Float, b:Float):Float { return Math.max(a,b); }
	public function abs(x:Float):Float { return Math.abs(x); }
	public function round(x:Float):Float {return Math.round(x); }
	public function pow(x:Float,n:Float):Float { return Math.pow(x,n); }
	public function sin(x:Float):Float { return Math.sin(x); }
} // class Main


